#ifndef CACTIVEHELPER_H_
#define CACTIVEHELPER_H_

#include <e32base.h>

template<class T>
class CActiveHelper;

template<class T>
struct MActiveHelperCallback
	{
	virtual void MActiveHelperCallbackRunL(CActiveHelper<T>* aActiveHelper, T aUserData) = 0;
	virtual TInt MActiveHelperCallbackRunError(CActiveHelper<T>* aActiveHelper, T aUserData, TInt aError) = 0;
	virtual void MActiveHelperCallbackDoCancel(CActiveHelper<T>* aActiveHelper, T aUserData) = 0;
	virtual ~MActiveHelperCallback();
	};

template<class T>
class CActiveHelper : public CActive
	{
public:
	static CActiveHelper<T>* NewL(const TPriority& aPriority = EPriorityStandard);
	static CActiveHelper<T>* NewLC(const TPriority& aPriority = EPriorityStandard);
	virtual ~CActiveHelper();
	void SetActive(MActiveHelperCallback<T>* aTarget, T aUserData = NULL);
	T iUserData;
	
protected:
	void RunL();
	TInt RunError(TInt aError);
	void DoCancel();
private:
	MActiveHelperCallback<T>* iTarget;
	CActiveHelper(const TPriority& aPriority);
	void ConstructL();
	};

#include "CActiveHelper.hpp"

#endif /* CACTIVEHELPER_H_ */
